Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
How to implement conditions with boolean operators "and" and "or"?

How can I implement a condition using boolean operators and and or using firestore?

An example of what I want to do:

  this.itemsCollection = this.afs.collection<Message>('messages', ref => {
    let query: firebase.default.firestore.CollectionReference | firebase.default.firestore.Query = ref;
    query = ((query.where('senderId', '==', this._cs.senderId || '') && query.where('receiverId', '==', this.receiverId || ''))
      || (query.where('receiverId', '==', this._cs.senderId || '') && query.where('senderId', '==', this.receiverId || '')))
    return query;
  })
  this.items = this.itemsCollection.valueChanges();
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There is no option to do an OR on different fields in Firestore. You will have to execute multiple queries for this, and then merge the results in your application code.

To check an OR for multiple values on a single field is called an in condition in Firestore, and can be done with:

query.where('senderId', 'in', [this._cs.senderId, '']) 

The empty string here must literally exist in the document for the to match the condition. There is no way to filter for documents where senderId doesn't exist, as documents without a value for that field simply won't exist in the index that Firestore created for senderId.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda